package com.wangjiacai.hqlQuery.hql.condition.where;

import com.wangjiacai.hqlQuery.hql.condition.Condition;
import com.wangjiacai.hqlQuery.util.HqlUtil;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target({ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
@Condition(condition = NotIn.NotInCondition.class,column = NotIn.NotInCondition.class)
public @interface NotIn {

    String column() default "";

    String hql() default "";

    class NotInCondition implements Condition.Where<NotIn,Object>, Condition.Column<NotIn> {
        @Override
        public String where(NotIn notIn,String property,String column,Object obj,Object value) {
            return notIn.hql().equals("")?column+" not in(:"+property+")":column+" not in ("+ HqlUtil.parseHql(notIn.hql(),obj)+")";
        }

        @Override
        public String column(NotIn notIn, String property) {
            return notIn.column().equals("")?property:notIn.column();
        }
    }

}
